import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
/**
 * 显示  渲染
 */
export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	console.log('----- show ----', args[0][0]);
	const edit = document.querySelector<HTMLDivElement>('[data-feidao-id="zj-teacher-002"]');
	edit.classList.remove('display-n');

	const form_title = document.querySelector<HTMLSpanElement>('[data-feidao-id="form_title"]');

	const teacher_no = args[0][0].teacher_no;
	const form = document.querySelector<HTMLFormElement>('[data-feidao-id="form"]');

	fd.data.exam_name = args[0][0].exam_name;
	fd.data.exam_id = args[0][0].exam_id;
	fd.data.teacher_id = args[0][0].teacher_id;

	console.log(form, args[0][0].exam_name);
	if (teacher_no) {
		const param = {
			criteria: { teacher_no },
			page_size: 0,
			page_no: 1,
			asc: ['teacher_no']
		};
		const res = await nodejs('flippedclass', 'usable-exam-teacher-find', param);
		const data = res.dataArray[0];

		console.warn('....................................', data);
		form_title.innerHTML = '编辑老师';

		document.querySelector<HTMLSpanElement>('[data-feidao-form="exam_name"]').innerHTML = data.exam_name;
		document.querySelector<HTMLInputElement>('[data-feidao-form="teacher_no"]').value = data.teacher_no;
		document.querySelector<HTMLInputElement>('[data-feidao-form="teacher_name"]').value = data.teacher_name;
		document.querySelector<HTMLInputElement>('[data-feidao-form="discipline"]').value = data.discipline;
		document.querySelector<HTMLInputElement>('[data-feidao-form="bstype"]').value = data.bstype;
		document.querySelector<HTMLInputElement>('[data-feidao-form="invigilation_num"]').value = data.invigilation_num;
	} else {
		form_title.innerHTML = '新增老师';
		document.querySelector<HTMLSpanElement>('[data-feidao-form="exam_name"]').innerHTML = args[0][0].exam_name;
		document.querySelector<HTMLInputElement>('[data-feidao-form="teacher_no"]').value = '';
		document.querySelector<HTMLInputElement>('[data-feidao-form="teacher_name"]').value = '';
		document.querySelector<HTMLInputElement>('[data-feidao-form="discipline"]').value = '';
		document.querySelector<HTMLInputElement>('[data-feidao-form="bstype"]').value = '';
		document.querySelector<HTMLInputElement>('[data-feidao-form="invigilation_num"]').value = '';
	}
}